﻿namespace EyeOpen.DataAnnotations
{
	using System.ComponentModel.DataAnnotations;
	using EyeOpen.Validation;

	public class CsvAttribute 
		: ValidationAttribute
	{
		private readonly CsvValidator csvValidator = 
			new CsvValidator();

		public CsvAttribute(int minimum, string message)
		{
			Minimum = minimum;
			ErrorMessage = message;
		}

		public int Minimum
		{
			get;
			private set;
		}

		public override string FormatErrorMessage(string name)
		{
			return string.Format(ErrorMessage, Minimum);
		}

		public override bool IsValid(object value)
		{
			return csvValidator.Validate((string)value, Minimum);
		}
	}
}